Convert Option[Object] to Option[Int] Implicitly
Posted
by wheaties
on Stack Overflow
See other posts from Stack Overflow
or by wheaties
Published on 2010-03-20T01:38:03Z
Indexed on
2010/03/20
1:41 UTC
Read the original article
Hit count: 418
I'm working with legacy Java code which returns java.lang.object. I'm passing it into a function and I'd like to do some implicit conversions as such:
implicit def asInt( _in:Option[Object] ) = _in asInstanceOf[ Option[Int] ]
implicit def asDouble( _in:Option[Object] = _in asInstanceOf[ Option[Double] ]
private def parseEntry( _name:String, _items:Map[String,Object] ) = _name match{
case docName.m_Constants =>
new Constants( _items get( Constants m_Epsilon ), _items get( Constant m_Rho ),
_items get( Constants m_N ) )
Technically it goes on but I keep getting the same errors: expected Int, Option[Object] found.
How have I done my implicits wrong? I was hoping it would do the transformation for me instead of me having to write "asInstanceOf" each and every time.
© Stack Overflow or respective owner